package com.controller.library;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.library.TGetExamInfoAction;
import com.bean.library.PaperInfo;

public class TCheckExamInfoServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6551227057605871049L;
	public void doPost(HttpServletRequest request,HttpServletResponse response){
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		if(request.getSession().getAttribute("selectedCourseId")!=null){
			int paperId = Integer.parseInt(request.getParameter("paper_id"));
			String paperName = request.getParameter("paper_name");
			TGetExamInfoAction tGetExamInfoAction = new TGetExamInfoAction();
			PaperInfo paperInfo = tGetExamInfoAction.getPaperInfo(paperId);
			if(paperInfo!=null){
				request.getSession().setAttribute("paperInfo", paperInfo);
				try {
					response.sendRedirect("/Exam1/teacher/t_page/t_exam_info.jsp");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			else{
				request.getSession().setAttribute("paperName", paperName);
				try {
					response.sendRedirect("/Exam1/teacher/t_page/t_exam_info.jsp");
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
